package com.wave.service;

import com.alibaba.fastjson.JSONObject;
import com.wave.entity.Deliver;
import com.wave.entity.LAF;
import com.wave.mapper.DeliverMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeliverService {
    @Autowired
    private DeliverMapper deliverMapper;

    public int createDeliver (Deliver deliver) {
        return deliverMapper.createDeliver(deliver);
    }

    public int alterDeliverType (int id, String type) {
        return deliverMapper.alterDeliverType(id, type);
    }

    public int changeLafDeliver (int target, String type) {
        return deliverMapper.changeLafDeliver(target, type);
    }

    public int otherDeliverChange(int id, String type){
        return deliverMapper.otherDeliverChange(id,type);
    }

    public List<Deliver>getMyDeliver(String author){
        return deliverMapper.getMyDeliver(author);
    }

    public JSONObject list(String dTarget, String dAuthorName, String dType, int pageNum, int pageSize) {
        int pageStart = (pageNum - 1) * pageSize; //加载起始
        JSONObject delList = new JSONObject();
        List<Deliver> list = deliverMapper.list(dTarget, dAuthorName, dType, pageStart, pageSize);
        int total = deliverMapper.countDel(dTarget, dAuthorName);
        delList.put("delList", list);
        delList.put("total", total);
        return delList;
    }

    public List<Deliver>getLAFDeliver(int id){
        if (deliverMapper.selectLAFDeliver(id) > 0){
            return deliverMapper.getLAFDeliver(id);
        }
        return null;
    }

    public int selectLAFDeliver (int id) {
        return deliverMapper.selectLAFDeliver(id);
    }

    public Deliver getDeliverDetail(int id){
        return deliverMapper.getDeliverDetail(id);
    }

    public int getDetailTarget(int id){
        return deliverMapper.getDetailTarget(id);
    }

    public String getType(int id){
        return deliverMapper.getType(id);
    }

}
